<template>
	<uni-search-bar @confirm="toSearch" placeholder="请输入搜索路线" v-model="searchKey" />
	<swiper style="height: 200px;" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
		<swiper-item v-for="(item,index) in lunboList" :key="index">
			<view class="swiper-item">
				<image style="width: 100%;" :src="item.url" mode=""></image>
			</view>
		</swiper-item>

	</swiper>
</template>

<script setup>
	import {
		onLoad
	} from "@dcloudio/uni-app"
	import {
		ref
	} from 'vue'
	import {
		CONFIG
	} from "../../utils/config";
	const searchKey = ref("")

	function toSearch() {
		if (searchKey.value == "") {
			uni.showToast({
				title: "请输入查询的公交地图路线",
				icon: "none"
			})
		} else {
			window.location.href =
				`https://uri.amap.com/line?name=${searchKey.value}&city=029&callnative=0`
		}
	}



	onLoad(() => {
		getLunbo()
		getCurrentPos()
	})

	const lunboList = ref([])
	async function getLunbo() {
		let res = await uni.$get(CONFIG.leanCloud_url + "/1.1/classes/Lunbo")
		if (res.statusCode == 200) {
			lunboList.value = res.data.results
		}
		console.log(lunboList.value)

	}

	function getCurrentPos() {
		uni.getLocation({
			success: function(res) {
				console.log('当前位置的经度：' + res.longitude);
				console.log('当前位置的纬度：' + res.latitude);
			}
		})
	}
</script>

<style lang="scss" scoped>

</style>